/*
 * Copyright (C) 2011 by Fabien Barbero
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package com.flickr.api;

import com.flickr.api.auth.AuthenticationServiceImpl;
import com.flickr.api.auth.Caller;
import com.flickr.api.photos.Exif;
import com.flickr.api.photos.Photo;
import com.flickr.api.photos.PhotoContext;
import com.flickr.api.photos.PhotoInfos;
import com.flickr.api.photos.PhotoSize;
import com.flickr.api.photos.PhotosService;
import com.flickr.api.photos.PhotosServiceImpl;
import java.util.List;
import static junit.framework.Assert.*;

/**
 *
 * @author Fabien Barbero
 */
public class PhotosServiceTester implements ServiceTester {

    @Override
    public void test(ApiKey key, AuthenticationServiceImpl authService, Caller caller, LocalCache cache) throws Exception {
        PhotosService photosService = new PhotosServiceImpl(key, authService, cache);
        List<Photo> photos = photosService.getContactsPhotos();
        assertNotNull(photos);
        assertFalse(photos.isEmpty());
        LOGGER.info(photos.toString());

        PhotoContext context = photosService.getContext(photos.get(0));
        assertNotNull(context);
        assertNotNull(context.getPreviousPhoto());
        assertNull(context.getNextPhoto());

        List<Exif> exifs = photosService.getExif(photos.get(0));
        assertFalse(exifs.isEmpty());

        List<PhotoSize> sizes = photosService.getSizes(photos.get(0));
        assertFalse(sizes.isEmpty());

        PhotoInfos infos = photosService.getInfos(photos.get(0));
        assertNotNull(infos);
        assertNotNull(infos.getDates().getLastUpdateDate());
        assertNotNull(infos.getDates().getPostedDate());
        assertNotNull(infos.getDates().getTakenDate());
        assertNotNull(infos.getDescription());
        assertNotNull(infos.getEditability());
        assertNotNull(infos.getGeoPermission());
        assertNotNull(infos.getLocation());
        assertNotNull(infos.getNotes());
        assertNotNull(infos.getOwner().getId());
        assertNotNull(infos.getOwner().getLocation());
        assertNotNull(infos.getOwner().getRealName());
        assertNotNull(infos.getOwner().getUserName());
        assertNotNull(infos.getPublicEditability());
        assertNotNull(infos.getTags());
        assertNotNull(infos.getTitle());
        assertNotNull(infos.getUsage());
        assertNotNull(infos.getVisibility());
        
        Photo photo = Photo.create("5653602215");
        LOGGER.debug("modifying photo {}", photo.getTitle());
        photosService.setMeta(photo, "Test", "Test");
    }
}
